package com.tllq.zhongkang.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tllq.zhongkang.entity.Insider;
import com.tllq.zhongkang.mapper.InsiderMapper;
import com.tllq.zhongkang.service.IsiderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class IsiderServiceImpl extends ServiceImpl<InsiderMapper, Insider> implements IsiderService {
    Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    InsiderMapper insiderMapper;

    @Override
    public List<Map<String,String>> findBymobile(String mobile) {
       List<Map<String,String>> mapList = new ArrayList<>();
        List<String> crdnos = insiderMapper.findBymobile(mobile);
        for (String crdno : crdnos) {
            Map<String,String> map =new  HashMap<>();
            map.put("cardNo",crdno);
            mapList.add(map);
        }
        return mapList;
    }

    @Override
    public Map<String,String> findById(Integer id) {
        try {
            Insider insider = insiderMapper.findById(id);
            Map<String,String> map  = new HashMap<>();
            map.put("cardNo",insider.getCardNo());
            map.put("integration",insider.getIntegration().toString());
            map.put("balance",insider.getBalance().toString());
            return map;
        } catch (Exception e) {
            return null;
        }

    }
}
